package com.ruoyi.business.service.impl;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.business.domain.Waterchillerhis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ProtectivegashisMapper;
import com.ruoyi.business.domain.Protectivegashis;
import com.ruoyi.business.service.IProtectivegashisService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author DL
 * @date 2025-07-07
 */
@Service
public class ProtectivegashisServiceImpl implements IProtectivegashisService 
{
    @Autowired
    private ProtectivegashisMapper protectivegashisMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param ID 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public Protectivegashis selectProtectivegashisByID(Long ID)
    {
        return protectivegashisMapper.selectProtectivegashisByID(ID);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param protectivegashis 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<Protectivegashis> selectProtectivegashisList(Protectivegashis protectivegashis)
    {
        return protectivegashisMapper.selectProtectivegashisList(protectivegashis);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param protectivegashis 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertProtectivegashis(Protectivegashis protectivegashis)
    {
        return protectivegashisMapper.insertProtectivegashis(protectivegashis);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param protectivegashis 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateProtectivegashis(Protectivegashis protectivegashis)
    {
        return protectivegashisMapper.updateProtectivegashis(protectivegashis);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param IDs 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteProtectivegashisByIDs(Long[] IDs)
    {
        return protectivegashisMapper.deleteProtectivegashisByIDs(IDs);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param ID 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteProtectivegashisByID(Long ID)
    {
        return protectivegashisMapper.deleteProtectivegashisByID(ID);
    }

    @Override
    public Map<String, Object> getProtectiveDataBetween(LocalDateTime startTime, LocalDateTime endTime) {
        // 查询数据库获取数据
        List<Protectivegashis> dataList = protectivegashisMapper.findByTimestampBetween(startTime, endTime);

        // 处理数据格式
        Map<String, Object> result = new HashMap<>();
        String[] xdata = new String[dataList.size()];
        double[] Gas1RealRate = new double[dataList.size()];
        double[] Gas2RealRate = new double[dataList.size()];

        // 定义格式化器
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

        for (int i = 0; i < dataList.size(); i++) {
            Protectivegashis data = dataList.get(i);
            xdata[i] = sdf.format(data.getEventTime());
            Gas1RealRate[i] = data.getGas1RealRate() != null ? data.getGas1RealRate().doubleValue() : 0.0;
            Gas2RealRate[i] = data.getGas2RealRate() != null ? data.getGas2RealRate().doubleValue() : 0.0;
        }

        result.put("xdata", xdata);
        result.put("Gas1RealRate", Gas1RealRate);
        result.put("Gas2RealRate", Gas2RealRate);

        return result;
    }
}
